<%@ page language="java" import="java.util.*,cn.ac.cintcm.dataconverge.researchsubject.domain.*" pageEncoding="UTF-8"%>
<%@page import="com.hs.core.page.PageUtil,com.hs.core.utils.*"%>
<%@page import="cn.ac.cintcm.dataconverge.util.Constants;"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String imagePath = path + "/index/";
Subject obj = (Subject)request.getAttribute("subject");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title><%=Constants.APP_TITLE %>--课题支出经费管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="<%=path%>/index/Themes/com/style.css" rel="stylesheet" type="text/css" /> 
    <script src="<%=path%>/index/Scripts/Script.js" language="javascript" type="text/javascript"></script>
     <script src="<%=path%>/js/common.js" language="javascript" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" src="<%=path %>/js/My97DatePicker/WdatePicker.js"></script>
    <script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>dwr/interface/subject.js'></script> 
    <script type="text/javascript">
    function saveData(){
       var fundNum = dwr.util.getValue("receivie");
       var fundYear = dwr.util.getValue("belongyear");
       var subjectId = dwr.util.getValue("subjectId");
       var fundId = dwr.util.getValue("fundId");
        
       var fundType = '<%=Constants.FUND_P%>';
       var userfor = dwr.util.getValue("fundUse"); 
       
       var flag = true;
       if(!userfor){
       		alert("请选择经费用途!"); 
       		flag = false;
       		return; 
       }
       if(isNull(fundNum)){
       		alert("请输入经费金额!");
       		form1.receivie.focus();
       		flag = false;
       		return; 
       }
       if(!isDigital(fundNum)){
            	alert("请输入正确经费金额!");
       			form1.receivie.focus();
       			flag = false;
       		    return; 
       }
       if(isNull(fundYear)){
       		alert("请选择经费所属年份!");
       		form1.belongyear.focus();
       		flag = false;
       		return; 
       }
       if(flag)
        subject.saveFund(subjectId,fundId,fundNum,fundYear,fundType,userfor,callBackForSave);
    }
    function callBackForSave(message){
       if("1" == message){
         alert("支出经费录入成功");
         window.location.replace(document.location.href);
         window.opener.location.reload();
       }
    }
    function selectRow(fundId){
       subject.getFundDetail(fundId,callBackGetInfo);
    }
    function callBackGetInfo(message){
    	var messageStr = message;
    	var dataArr;
    	if(null != messageStr && ''!= messageStr)
    	    dataArr = messageStr.split(',');
        if(dataArr.length > 0){
           dwr.util.setValue("fundId",dataArr[0]);
           dwr.util.setValue("receivie",dataArr[1]);
           dwr.util.setValue("belongyear",dataArr[2]); 
        }
    }
    function delFund(fundId){
       if(confirm("确认要删除这笔费用吗?"))
       subject.delFund(fundId,callBackDel);
    }
    function callBackDel(message){
    	 if("1" == message){
	         alert("删除成功");
	         window.location.replace(document.location.href);
	         window.opener.location.reload();
       }
    }
    
    </script>
  </head>
  
  <body class="rtm_body">
  <form name="form1">
    <div class="r_rtm_tb_mg1">
        <div class="r_rtm_tb1">
            <span>
                <img src="<%=imagePath%>Themes/com/idt_tb_pass.gif" />&nbsp;&nbsp;支出经费管理</span>
        </div>
    </div>
    <div>
        <table cellspacing="2" cellpadding="0" width="100%" class="idt_item_mg" id="Table2">
            <tr>
                <td class="fim_r" align="right" colspan="8">
                    <fieldset class="com_fieldset" align="center">
                        <legend class="com_legend">课题信息概览</legend>
                        <table border="0" cellpadding="0" cellspacing="1" width="100%" class="com_fieldset_tab">
                            <tr>
                                <td class="fim_l">
                                    课题名称：</td>
                                <td class="fim_r" colspan=3>
                                    <%=obj.getSubjectname() %>
                                    <input type="hidden" name="subjectId" value="<%=obj.getId() %>"/>
                                    </td>
                               
                            </tr> 
                            <tr>
                                <td class="fim_l">
                                    课题编号：</td>
                                <td class="fim_r">
                                     <%=StringUtilTool.NULL2Blank(obj.getSnumber()) %></td> 
                                <td class="fim_l">
                                    课题状态：</td>
                                <td class="fim_r">
                                     <%=Constants.getSubjectStatus(obj.getState()) %></td> 
                            </tr> 
                            <tr>
                                <td class="fim_l">
                                    负责人：</td>
                                <td class="fim_r">
                                    <%if(obj != null){
                                     Set res = obj.getSubRes();
                                     Iterator it = res.iterator();
                                     int j = 0;
                                     while(it.hasNext()){
                                    	 
                                         SubRes rearcher = (SubRes)it.next();
                                         if(Constants.researcher_role_chargeman.equals(rearcher.getResRole()+"")){
                                         	out.println(rearcher.getRes()==null?"":rearcher.getRes().getName()+"&nbsp;"); 
                                         	j++;
                                         } 
                                     }
                                   }  %>
                                    </td>
                                <td class="fim_l">
                                    总经费：</td>
                                <td class="fim_r">
                                     <%=StringUtilTool.NULL2Blank(obj.getPermitfund()+"") %></td> 
                            </tr> 
                        </table>
                    </fieldset>
                </td>
            </tr>
        </table>
    </div> 
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <div class="content">
                    <table width="*" cellpadding="0" cellspacing="1" class="dg_borderstyle" id="Table4">
                        <tr>
                            <td class="dg_headerstyle" align="center"  width="5%">
                                选择
                           </td>
                            <td class="dg_headerstyle" align="center"  width="5%">
                                 序号</td>
                            <td class="dg_headerstyle">
                                 支出经费类型</td>
                            <td class="dg_headerstyle">
                                金额</td>
                            <td class="dg_headerstyle">
                                支出日期</td>
                                 <td class="dg_headerstyle">
                                所属年份</td>
                            <td class="dg_headerstyle">
                                录入人</td> 
                                <td class="dg_headerstyle">
                                删除</td> 
                        </tr>
                        <%
                          Set funds =  obj.getFunds();
                          if(null != funds && funds.size()!= 0){
                        	  Iterator iter = funds.iterator();
                        	  int  i =0;
                        	  while(iter.hasNext()){ 
                        		  ResmanSubjectFund fund = (ResmanSubjectFund)iter.next();
                        		  if(Constants.FUND_P.equals(fund.getFundtype())){
                        		  	i++;
                        		  }else{
                        			  continue;
                        		  }
                          
                        %>
                        <tr class="dg_alternatingitemstyle">
                            <td align="center"  width="5%">
                                 <input type="radio" name="selectFund" onclick="selectRow('<%=fund.getId() %>')" value="<%=fund.getId() %>" /></td>
                            <td align="center" width="5%">
                                <%=i %></td>
                            <td align="center">
                                  <%
                                   if(null != fund.getUsefor()){
                                	   if("1".equals(fund.getUsefor()))
                                		   out.println("<font color=red>材料费</font>");
                                	   if("2".equals(fund.getUsefor()))
                                		   out.println("<font color=red>测试化验加工费</font>");
                                	   if("3".equals(fund.getUsefor()))
                                		   out.println("<font color=red>差旅费</font>");
                                	   if("4".equals(fund.getUsefor()))
                                		   out.println("<font color=red>会议费</font>");
                                	   if("5".equals(fund.getUsefor()))
                                		   out.println("<font color=red>出版费</font>");
                                	   if("6".equals(fund.getUsefor()))
                                		   out.println("<font color=red>专家咨询费</font>");
                                	   if("7".equals(fund.getUsefor()))
                                		   out.println("<font color=red>劳务费</font>");
                                	   if("8".equals(fund.getUsefor()))
                                		   out.println("<font color=red>其它</font>");  
                                   }
                                  %>
                            </td>
                            <td>
                                <%=fund.getReceivefund() %>
                            </td>
                            <td>
                                <%=Tools.getDateStringByDate1(fund.getRecorddate()) %>
                            </td>
                            <td>
                                <%=fund.getYear()%>
                            </td> 
                             <td>
                                <%=fund.getRes()==null?"":fund.getRes().getName() %>
                            </td> 
                            <td align="center">
                                <img src="<%=imagePath %>Themes/com/68design.net_registration1_(delete)_16x16.gif" onclick="javascript:delFund('<%=fund.getId() %>');"
                                    alt="删除" />
                            </td> 
                        </tr> 
                        <%}}else{ %>
                         <tr class="dg_alternatingitemstyle"> 
                            <td colspan="8" align="center">
                                <font color=red>没有找到记录</font>
                            </td>  
                        </tr>  
                        <%} %>
                    </table>  
                </div>
            </td>
        </tr>
    </table>
    
    <table cellpadding="0" cellspacing="0" width="100%" height="100%" id="Table8">  
        <tr>
            <td valign="top" height="100%">
                <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="Table11">
                    <tr>
                        <td valign="top" >
                            <!------------------ 标题栏 ------------------>
                            <!--- 标题 ---->
                            <table class="idt_tle_mg" cellspacing="0" cellpadding="0" width="100%">
                                <tr >
                                    <td class="idt_tle_i">
                                        <img id="imgForm6" src="<%=basePath%>index/Themes/com/idt_tle_o.gif"></td>
                                    <td class="idt_tle_f1">
                                        添加支出经费</td>
                                </tr>
                            </table>
                            <!--- 内容 --->
                            <div id="tdForm">
                                <table border="0" cellpadding="0" cellspacing="1" width="100%" class="idt_fim_mg">
                                    <tr>
                                        <td class="fim_l" width="15%">
                                           经费用途</td>
                                        <td class="fim_r"  colspan="3">
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="1">材料费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="2">测试化验加工费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="3">差旅费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="4">会议费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="5">出版费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="6">专家咨询费
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="7">劳务费  
	                                        <input type="radio" name="fundUse" class="com_textbox"  value="8">其它  
                                        </td> 
                                    </tr> 
                                    <tr>
                                        <td class="fim_l" width="15%">
                                           支出金额</td>
                                        <td class="fim_r" width="35%">
	                                        <input type="text" name="receivie" class="com_textbox" style="width:100%" >
	                                         <input type="hidden" name="fundId" class="com_textbox"  >
                                        </td>
                                         <td class="fim_l" width="15%">
                                           所属年份</td>
                                        <td class="fim_r" >
	                                      <input type="text" class="Wdate" id="belongyear" value="<%=obj==null?Tools.getYear():obj.getBelongyear() %>" style="width:99%" name="belongyear"   onFocus="WdatePicker({el:'belongyear',dateFmt:'yyyy'})" /></td>
                                             
                                    </tr> 
                                </table>
                                <table cellspacing="0" cellpadding="0" width="100%" class="idt_bottom_mg" border="0">
                                    <tr>
                                        <td align="right">
                                            <input type="button" value="保存"   class="com_btn2"   onclick="saveData()" />
                                 <input type="button" value="关闭"   class="com_btn2"   onclick="window.close();" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                </table>
      </form>
</body>
</html>
